package com.sxfq.loansupermarket.backsystem.modular.doctorLooked.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.dao.TechnologyConsumableDao;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.entity.SearchTechnologyConsumableInfo;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.entity.TechnologyConsumableInfo;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.service.ITechnologyConsumableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class TechnologyConsumableServiceImpl implements ITechnologyConsumableService {
    @Autowired
    private TechnologyConsumableDao dao;

    @Override
    public List<TechnologyConsumableInfo> selectPageListByQueryGetMap(Page<TechnologyConsumableInfo> page, SearchTechnologyConsumableInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore()) && !"请选择".equals(searchInfo.getArrivalStore())) {
            String arrivalStore = "";
            String arrivalStore2[] = searchInfo.getArrivalStore().split(",");
            if (arrivalStore2.length == 1) {
                arrivalStore = arrivalStore2[0];
            } else {
                for (int i = 0; i < arrivalStore2.length; i++) {
                    if (i == (arrivalStore2.length - 1)) {
                        arrivalStore += "'" + arrivalStore2[i];
                    } else if (i == 0) {
                        arrivalStore += arrivalStore2[i] + "'" + ",";
                    } else {
                        arrivalStore += "'" + arrivalStore2[i] + "'" + ",";
                    }
                }
            }
            params.put("arrivalStore", "  t.arrival_store in ( '" + arrivalStore + "') ");
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getPayServiceName())) {
            params.put("payServiceName", searchInfo.getPayServiceName());
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPage(page, params);
    }

    public int getQueryPagesCount(Page<TechnologyConsumableInfo> page, SearchTechnologyConsumableInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore()) && !"请选择".equals(searchInfo.getArrivalStore())) {
            String arrivalStore = "";
            String arrivalStore2[] = searchInfo.getArrivalStore().split(",");
            if (arrivalStore2.length == 1) {
                arrivalStore = arrivalStore2[0];
            } else {
                for (int i = 0; i < arrivalStore2.length; i++) {
                    if (i == (arrivalStore2.length - 1)) {
                        arrivalStore += "'" + arrivalStore2[i];
                    } else if (i == 0) {
                        arrivalStore += arrivalStore2[i] + "'" + ",";
                    } else {
                        arrivalStore += "'" + arrivalStore2[i] + "'" + ",";
                    }
                }
            }
            params.put("arrivalStore", "  t.arrival_store in ( '" + arrivalStore + "') ");
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getPayServiceName())) {
            params.put("payServiceName", searchInfo.getPayServiceName());
        }
        return dao.getQueryPagesCount(page, params);
    }

    public List<TechnologyConsumableInfo> technologyConsumableExport(SearchTechnologyConsumableInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArrivalStore()) && !"请选择".equals(searchInfo.getArrivalStore())) {
            String arrivalStore = "";
            String arrivalStore2[] = searchInfo.getArrivalStore().split(",");
            if (arrivalStore2.length == 1) {
                arrivalStore = arrivalStore2[0];
            } else {
                for (int i = 0; i < arrivalStore2.length; i++) {
                    if (i == (arrivalStore2.length - 1)) {
                        arrivalStore += "'" + arrivalStore2[i];
                    } else if (i == 0) {
                        arrivalStore += arrivalStore2[i] + "'" + ",";
                    } else {
                        arrivalStore += "'" + arrivalStore2[i] + "'" + ",";
                    }
                }
            }
            params.put("arrivalStore", "  t.arrival_store in ( '" + arrivalStore + "') ");
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getPayServiceName())) {
            params.put("payServiceName", searchInfo.getPayServiceName());
        }
        return dao.technologyConsumableInfoExport(params);
    }
}